package com.helloandroid.paso.ui.mediaplayer;

import java.util.ArrayList;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class TrackSelectDialog {
	private Context context;

	public TrackSelectDialog(Context context) {
		this.context = context;
	}

	public void selectTrack(ArrayList<Track> list, int layout, int dialogItemID, int lv, int titleTextID, final ISelectDialogCallback callback) {
		final Dialog dialog = new Dialog(context);

		dialog.setContentView(layout);
		dialog.setTitle("Select track");
		dialog.setCancelable(true);
		ListView listView = (ListView)dialog.findViewById(lv);

		listView.setAdapter(new TrackAdapter(context, dialogItemID, list, titleTextID));

		// Send the selected track back to the caller and dismiss the dialog
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				callback.onTrackSelect((Track)parent.getItemAtPosition(position));
				dialog.dismiss();
			}
		});
		
		dialog.show();
	}
}
